﻿using System;
using System.IO;


namespace collabr8
{
    [Serializable]
    public class Clip : IDisposable
    {
        MemoryStream ms;
        private string name;
        private bool disposed = false;

        public Clip(string path, string name)
        {
            this.name = name;
            this.ms = new MemoryStream();
            if (File.Exists(path))
            {
                FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);
                file.CopyTo(ms);
                file.Close();
                file.Dispose();
            }
        }

        public void SaveFile(string folder)
        {
            FileStream file = new FileStream(folder+"\\"+name, FileMode.Create, FileAccess.Write);
            this.ms.WriteTo(file);
            file.Close();
            file.Dispose();
        }

        public string Name
        {
            get
            {
                return this.name;
            }
        }

        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    this.ms.Dispose();
                }
            }
            disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

    }
}
